﻿<?php
//************************************
//*** CONFIGURACAO DE PRODUCAO *******
//************************************


GLOBAL $LOGGER;

class Kernel {
	var $log;
	function setLog($tipo, $codigo, $message = '') {
		global $LOGGER;
		$this->log = $message;
		$LOGGER[] = array($tipo, $codigo, $message, date("m/d/Y"), date("G:i:s"));
	}

	function getLog(){
		return $this->log;
	}

	function showLogs($tipo = ''){
		global $LOGGER;
		for ($i = 0; $i < count($LOGGER); $i++ ){
			if ( $tipo == '' || $tipo == $LOGGER[$i][0] ){
				echo "<hr>>> " . $LOGGER[$i][4] . "(" . $LOGGER[$i][1] . ")" . " - ". $LOGGER[$i][2];
			}
		}
	}
	function getMessageLog($codigo){
		global $LOGGER;
		for ($i = 0; $i < count($LOGGER); $i++ ){
			if ( $codigo == $LOGGER[$i][1] ){
				return $LOGGER[$i][2];
			}
		}
	}
	
	function getClass ( $zAPI_name ){
		if ( $zAPI_name == "zNews" ) {
			return ROOT_CLASS . 'zNews/zNews.class.php';
		} else if ( $zAPI_name == "Util" ) {
			return ROOT_CLASS . 'Util/Util.class.php';
		} else if ( $zAPI_name == "zAccess" ) {
			return ROOT_CLASS . 'zAccess/zAccess.class.php';
		} else if ( $zAPI_name == "zSql" ) {
			return ROOT_CLASS . 'zSql/zSql.class.php';
		} else if ( $zAPI_name == "zMail" ) {
			return ROOT_CLASS . 'zMail/zMail.class.php';
		} else if ( $zAPI_name == "zSendMail" ) {
			return ROOT_CLASS . 'zSendMail/zSendMail.class.php';
		} else if ( $zAPI_name == "zMural" ) {
			return ROOT_CLASS . 'zMural/zMural.class.php';
		} else if ( $zAPI_name == "zMaps" ) {
			return ROOT_CLASS . 'zMaps/zMaps.class.php';
		} else if ( $zAPI_name == "zUsuario" ) {
			return ROOT_CLASS . 'zUsuario.class.php';
		} else if ( $zAPI_name == "zSessionApp" ) {
			return ROOT_CLASS . 'zSession/zSession.class.php';
		} else if ( $zAPI_name == "DataAccessObject" ) {
			return ROOT_CLASS . 'DataAccessObject/DataAccessObject.class.php';
		} else if ( $zAPI_name == "BusinessObject" ) {
			return ROOT_CLASS . 'BusinessObject/BO.class.php';
		} else if ( $zAPI_name == "zForms" ) {
			return ROOT_CLASS . 'zForms/zForms.class.php';
		} else if ( $zAPI_name == "zUpload" ) {
			return ROOT_CLASS . 'zUpload/zUpload.class.php';
		} else if ( $zAPI_name == "DAOAcess" ) {
			return ROOT_CLASS . 'DAOAcess/DAOAcess.class.php';
		} else if ( $zAPI_name == "zAcessUser" ) {
			return ROOT_CLASS . 'zAcessUser/zAcessUser.class.php';
		}
	}
	function getContextPath(){
		return "";
	}

	function getRandonKey($len, $chars = 'abcdefghijklmnopqrstuvxzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'){
		$string = '';
		for ($i = 0; $i < $len; $i++){
			$pos = rand(0, strlen($chars)-1);
			$string .= $chars{$pos};
		}
		return $string;
	}

	function randomkeys($length)
	{
	  $pattern = "1234567890abcdefghijklmnopqrstuvwxyz";
	  for($i=0;$i<$length;$i++)
	  {
	    if(isset($key))
	      $key .= $pattern{rand(0,35)};
	    else
	      $key = $pattern{rand(0,35)};
	  }
	  return $key;
	}
	
	function stringToSqlDate($strData) {
		// Recebemos a data no formato: dd/mm/aaaa
		// Convertemos a data para o formato: aaaa-mm-dd
		if ( strpos($strData, "/") != false ) {
			$strDataFinal .= implode('-', array_reverse(explode('/',$strData)));
		}
		return $strDataFinal;
	}
	
	function sqlDateToString($strData) {
		// Recebemos a data no formato: dd/mm/aaaa
		// Convertemos a data para o formato: aaaa-mm-dd
		if ( strpos($strData, "-") != false ) {
			$strDataFinal .= implode('/', array_reverse(explode('-',$strData)));
		}
		return $strDataFinal;
	}

}

$kernel = new Kernel();


class Properties {
	var $className = "Properties";
	var $attributes;
	function add( $name, $value ){
	//echo "(".$value.")";
		$this->attributes[] = array('name'=>$name, 'value'=>$value);
	}
	function set( $name, $value ){
		$this->attributes[] = array('name'=>$name, 'value'=>$value);
	}
	function get( $item = '' ){
		if ( $item === '' ){
			return $this->attributes;
		} else {
			return  $this->attributes[$item];
		}
	}
	function length(){
		return count($this->attributes);
	}
	function getValue( $name ){
		for ($i = 0; $i < count($this->attributes); $i++ ){
			$v = $this->attributes[$i];
			if ( $v['name'] == $name ){
				return $v['value'];
			}
		}
		return false;
	}
	function getJson( $fields = '' ){
		$stb = new StringBuffer();
		$stb->append("{");
		$aux = "";
		for ($i = 0; $i < count($this->attributes); $i++ ){
			$v = $this->attributes[$i];
			if ( $fields == "" ){
				$stb->append($aux . $v['name'] . " : '" . $this->prepareData( $v['value'] ) . "'");
			} else {
				$arrFields = explode(",", $fields);
				for ( $i = 0; $i < count($arrFields); $i++ ) { 
					if ( trim( $arrFields[$i] ) == $v['name'] ){
						
						$stb->append($aux . $v['name'] . ": '" . $this->prepareData( $v['value'] ) . "'");
					}
				}
			}
			$aux = ",";
		}
		$stb->append("}");
		return $stb->toString();
	}
	function prepareData( $data ){
		$data = str_replace( "\n", "\\n", $data);
		return $data;
	}
}

	function tranformDataObjectToJSON( $dataObject, $fields = '' ){
		$stb = new StringBuffer();
		$stb->append("{");
		$aux = "";
		foreach ( dataObject as $name => $value ) { 
			if ( $fields == "" ){
				$stb->append($aux . "$name : '" . $this->scapeDataForJavaScriptVariable( $this->attributes[$name]["data"] ) . "'");
			} else {
				$arrFields = explode(",", $fields);
				for ( $i = 0; $i < count($arrFields); $i++ ) { 
					if ( trim( $arrFields[$i] ) == $name ){
					$stb->append($aux . "$name : '" . $this->scapeDataForJavaScriptVariable( $this->attributes[$name]["data"] ) . "'");
					}
				}
			}
			$aux = ",";
		}
		$stb->append("}");
		return $stb->toString();
	}
	function scapeDataForJavaScriptVariable( $data ){
		$data = str_replace( "\n", "\\n", $data);
		return $data;
	}

/*
This file is part of J4PHP - Ensembles de propriétés et méthodes permettant le developpment rapide d'application web modulaire
Copyright (c) 2002-2004 @PICNet

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE
as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU LESSER GENERAL PUBLIC LICENSE for more details.

You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

/*
* SuperClass Object offrant toutes les fonctionnalités de gestion des objets tel que le nom de la class courante, le parent de la class courant s'il y a.
* Cette class permet aussi l'instanciation de la superClass général de gestion d'erreur ErrorManager
* 
* @module APIC
* @package core
* @update $Date: 2006/06/02 15:20:44 $
* @version 1.0
* @author diogène MOULRON <logiciel@apicnet.net>
* @see ErrorManager.php
*/ 
class Object{

	/**
	 * Constructeur : Object::Object()
	 * 
	 * @return 
	 **/
	function Object(){
	}
	
	function getNewId(){
		$char_list = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

		for($i = 0; $i < 20; $i++){
			$sid .= substr($char_list, rand(0, strlen($char_list)), 1);
		}
		return md5($sid);
	}
	
	/**
	 * Object::className()
	 * 
	 * @return le nom de la class courante ayant fait appel a cette fonction
	 **/
	function className(){return get_class($this);}
	
	/**
	 * Object::getParentClass()
	 * 
	 * @param $object
	 * @return 
	 **/
	function getParentClass($object){return get_parent_class($object);}
	
	/**
	 * Object::equals()
	 * 
	 * @param $object
	 * @return 
	 **/
	function equals(&$object){
		if (Object::validClass($object)){
			return TRUE;
		}
		return FALSE;
	}
	
	/**
	 * Object::toString()
	 * 
	 * @return 
	 **/
	function toString(){return 'Object';}
	
	/**
	 * Object::serialize()
	 * 
	 * @return 
	 **/
	function serialize(){
		return serialize($this);
	}
	
	/**
	 * Object::serialize()
	 * 
	 * @return 
	 **/
	function load(){
	}
	
	/**
	 * Returns a copy of this object instance.
	 *
	 * @access	public
	 * @return	mixed
	 */
	function cloneNode(){	return $this;}
	
	/**
	 * Object::hashValue()
	 * 
	 * @return 
	 **/
	function hashValue(){return md5(serialize($this));}
	
	/**
	 * Object::validClass()
	 * 
	 * @param $object
	 * @param string $classname
	 * @return 
	 **/
	function validClass($object, $classname = 'object'){
		return (is_object($object) && ($object->className()==$classname || is_subclass_of($object, $classname)));
	}
}
?>